﻿#ifndef PROGRESSINFO_H
#define PROGRESSINFO_H

#include "qbaseentity.h"
#include <progress.h>

class ProgressInfo : public QBaseEntity
{
    Q_OBJECT
    // 使用 Q_PROPERTY 宏定义属性
    Q_PROPERTY(Progress progress READ getProgress WRITE setProgress)
    Q_PROPERTY(bool enabled READ getEnabled WRITE setEnabled)
    Q_PROPERTY(uint64_t runTime READ getRunTime WRITE setRunTime)
    Q_PROPERTY(QList<float> cpuUsageList READ getCpuUsageList WRITE setCpuUsageList)
    Q_PROPERTY(float cpuUsage READ getCpuUsage WRITE setCpuUsage)
    Q_PROPERTY(QString stateMsg READ getStateMsg WRITE setStateMsg)
    Q_PROPERTY(uint64_t memory READ getMemory WRITE setMemory)
    Q_PROPERTY(uint64_t virtualMemory READ getVirtualMemory WRITE setVirtualMemory)
    Q_PROPERTY(uint64_t ioRead READ getIoRead WRITE setIoRead)
    Q_PROPERTY(uint64_t ioWrite READ getIoWrite WRITE setIoWrite)

public:
    explicit ProgressInfo(QObject *parent = nullptr);
    ~ProgressInfo();

    QJsonObject toJsonObject(PropertiesType type = AllProperty, QStringList propertyList = QStringList()) const override;
    void fromJsonObject(const QJsonObject &jsonObject) override;

    Progress getProgress() const;
    void setProgress(const Progress &value);

    bool getEnabled() const;
    void setEnabled(bool value);

    uint64_t getRunTime() const;
    void setRunTime(const uint64_t &value);

    float getCpuUsage() const;
    void setCpuUsage(float value);

    QString getStateMsg() const;
    void setStateMsg(const QString &value);

    uint64_t getMemory() const;
    void setMemory(const uint64_t &value);

    uint64_t getVirtualMemory() const;
    void setVirtualMemory(const uint64_t &value);

    uint64_t getIoRead() const;
    void setIoRead(const uint64_t &value);

    uint64_t getIoWrite() const;
    void setIoWrite(const uint64_t &value);

    QList<float> getCpuUsageList() const;
    void setCpuUsageList(const QList<float> &value);

private:
    Progress progress;

    bool enabled;     //是否启动
    uint64_t runTime; //运行时长（s）
    QList<float> cpuUsageList;
    float cpuUsage;         //cpu占用率
    QString stateMsg;       //运行信息
    uint64_t memory;        //内存
    uint64_t virtualMemory; //虚拟内存
    uint64_t ioRead;        //io读
    uint64_t ioWrite;       //io写
};
Q_DECLARE_METATYPE(ProgressInfo) //注册到元数据对象
#endif                           // PROGRESSINFO_H
